package model

import "gorm.io/gorm"

type Coupon struct {
	gorm.Model
	Title       string `gorm:"type:varchar(150); not null; commit:'卷名'"`
	TypeId      int64  `gorm:"type:int; not null; commit:'类型Id'"`
	Comment     string `gorm:"type:varchar(150); not null; commit:'优惠卷内容'"`
	ClaimStatus int64  `gorm:"type:int; not null; commit:'是否领取: 0-没有领取,1-领取'"`
	Remaining   int64  `gorm:"type:int; not null; commit:'剩余数'"`
	Quantity    int64  `gorm:"type:int; not null; commit:'总发放量'"`
	Status      int64  `gorm:"type:int; not null;default:0; commit:'优惠卷状态: 0-未过期,1-已过期'"`
}

func (c *Coupon) CreateCoupon(db *gorm.DB) error {
	err := db.Create(&c).Error
	return err
}
func (c *Coupon) UpdateCoupon(db *gorm.DB, id, status int64) error {
	err := db.Model(&Coupon{}).Where("id=?", id).Update("status", status).Error
	return err
}
